package com.example.combwyaq.db;

import android.content.Context;

public class DaoManager {
    private DaoSession daoSession;
    private DaoMaster daoMaster;
    private Context context;

    public void init(Context context) {
        this.context = context;
    }

    public DaoMaster getDaoMaster() throws Exception {
        if (context==null){
            throw new Exception("context is null");
        }
        if (daoMaster==null){
            DaoMaster.DevOpenHelper food = new DaoMaster.DevOpenHelper(context, "paper");
            daoMaster=new DaoMaster(food.getWritableDatabase());
        }
        return daoMaster;
    }

    public DaoSession getDaoSession() throws Exception {
        if (daoSession==null){
            daoSession=getDaoMaster().newSession();
        }
        return daoSession;
    }

    public static DaoManager daoManager;
    public static DaoManager getInstance(){
        if (daoManager==null){
            daoManager=new DaoManager();
        }
        return daoManager;
    }

}
